import sys, contextlib
from io import StringIO
from support.utils.toolkit import Log
class Executor:
    @contextlib.contextmanager
    def catchOutIO():
        old_out = sys.stdout
        redirected_out = StringIO()
        sys.stdout = redirected_out
        yield redirected_out
        sys.stdout = old_out
        redirected_out.close()

    def run(res, globals):
        msg = []
        with Executor.catchOutIO() as io:
            try:
                exec(compile(res,"","exec"), globals)
            except Exception as e:
                Log.e(e)
            msg.append(io.getvalue())
        return {"type":1, "msg":msg}

